function checkPetName() {
    var petName = document.getElementById("petName");
    if (petName.value == "") {
        petName.classList.add("form-wrong");
        return false;
    } else {
        petName.classList.remove("form-wrong");
        return true;
    }
}

function checkPetType() {
    var petType = document.getElementById("petType");
    var inputPetTypeDiv = document.getElementById("inputPetTypeDiv");
    var petTypeValue = petType.options[petType.selectedIndex].value;
    if (petTypeValue == "none") {
        petType.classList.add("form-wrong");
        return false;
    } else {
        if (petTypeValue === "other") {
            inputPetTypeDiv.style.display = "block";
        } else {
            inputPetTypeDiv.style.display = "none";
        }
        petType.classList.remove("form-wrong");

        if (inputPetTypeDiv.style.display == "block") {
            var inputPetType = document.getElementById("inputPetType");
            if (inputPetType.value == "") {
                inputPetType.classList.add("form-wrong");
                return false;
            } else {
                inputPetType.classList.remove("form-wrong");
                return true;
            }
        } else {
            inputPetType.classList.remove("form-wrong");
            return true;
        }
    }
}

function checkBirthday() {
    var Birthday = document.getElementById("petBirthday");
    var BirthdayValue = Birthday.value;
    var BirthdayDate = new Date(BirthdayValue);
    var now = new Date();
    if (BirthdayDate > now) {
        alert('出生日期不能超过当前日期！');
        return false;
    }
}

function checkForm() {
    checkPetName();
    checkPetType();
    checkBirthday();
    if (!checkPetName() || !checkPetType() || checkBirthday()) {
        alert("信息填写错误！请检查后重新提交！");
        return false;
    }
}